﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;

namespace SilverlightCaptcha
{
    public partial class MainPage : UserControl
    {
        CaptchaServiceReference.CaptchaServiceSoapClient client;

        public MainPage()
        {
            InitializeComponent();
            imgCaptcha.Source = new BitmapImage(new Uri("http://localhost:2918/AntiBotImage.ashx"));

            client = new CaptchaServiceReference.CaptchaServiceSoapClient();
            client.IsValidCaptchaCompleted += new EventHandler<CaptchaServiceReference.IsValidCaptchaCompletedEventArgs>(client_IsValidCaptchaCompleted);
        }

        void client_IsValidCaptchaCompleted(object sender, CaptchaServiceReference.IsValidCaptchaCompletedEventArgs e)
        {
            if (e.Result)
            {
                lMessage.Content = "Success!";
            }
            else
            {
                lMessage.Content = "Invalid captcha!";
            }
        }

        private void btCheck_Click(object sender, RoutedEventArgs e)
        {
            client.IsValidCaptchaAsync(tbCaptcha.Text);
        }
    }
}
